

package cn.shengchao.examstar.dict.ohs.local.appservices;

import cn.shengchao.examstar.dict.acl.ports.repositories.IExamStarDictRepository;
import cn.shengchao.examstar.dict.acl.ports.message.DictDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Service
public class ExamStarDictAppService {

    @Autowired
    private IExamStarDictRepository examStarDictRepository;

    public Map<String, String> getAllDict() {
        List<DictDto> dictDtos = examStarDictRepository.getAllList();
        return dictDtos.stream()
            .collect(Collectors.groupingBy(DictDto::getDescription, Collectors.mapping(DictDto::getName, Collectors
                .joining(","))));
    }

    public Map<String, String> getAllDictItem() {
        List<DictDto> dictDtos = examStarDictRepository.getAllItemList();
        return dictDtos.stream()
            .collect(Collectors.groupingBy(DictDto::getId, Collectors.mapping(DictDto::getName, Collectors
                .joining(","))));
    }
}
